<script lang="ts" setup>
import { EChartsOption } from 'echarts';
import { onMounted, ref, watchEffect } from 'vue';

import useEcharts from '../hooks/use-echarts';

const props = withDefaults(
  defineProps<{
    options: EChartsOption;
    width?: string;
    height?: string;
  }>(),
  {
    width: '100%',
    height: '360px'
  }
);
const echartDivRef = ref<HTMLElement>();

onMounted(() => {
  const { setOptions } = useEcharts(echartDivRef.value!);

  watchEffect(() => {
    setOptions(props.options);
  });
});
</script>
<template>
  <div class="base-echart">
    <div ref="echartDivRef" :style="{ width: width, height: height }"></div>
  </div>
</template>
<style lang="less" scoped></style>
